package service.impl;

import dao.CommodityClassDao;
import dao.impl.CommodityClassDaoImpl;
import pojo.Commodity;
import pojo.CommodityClass;
import service.CommodityClassService;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品分类接口的实现类
 * @author 叶军军
 */
public class CommodityClassServiceImpl implements CommodityClassService {

    /**
     * 实例化CommodityClassDao
     */
    CommodityClassDao ccd=new CommodityClassDaoImpl();

    /**
     * 查询所有的商品分类
     */
    @Override
    public List<CommodityClass> queryCommodityClass() {
        return ccd.queryCommodityClass();
    }

    /**
     *根据搜索关键字查询商品分类
     */
    @Override
    public List queryCommodityClassByKey(String value) {
        List commodities=new ArrayList();
        List<CommodityClass> list=ccd.queryCommodityClassByKey(value);
        for(CommodityClass commodityClass:list){
            List<Commodity> comm=queryCommodityByClId(commodityClass.getClId());
            commodities.addAll(comm);
        }
        return commodities;
    }

    /**
     *根据父类Id查询商品集合
     */
    @Override
    public List<Commodity> queryCommodityByClId(int id) {
        return ccd.queryCommodityByClId(id);
    }
}
